package gorotine

import (
	"encoding/json"
	"fmt"
)

//定义一个结构体

type Server struct {
	ServerName string
	ServerIp   string
	ServerPort int
}

func JsonSerial() {
	server := new(Server)
	server.ServerName = "Demo-for-json"
	server.ServerIp = "127.0.0.1"
	server.ServerPort = 8080

	b, err := json.Marshal(server)
	if err != nil {
		fmt.Println("JsonSerial err : ", err)
		return
	}
	fmt.Println(string(b))
}

func JsonSerialMap() {
	server := make(map[string]interface{})
	server["ServerName"] = "Demo-for-json"
	server["ServerIp"] = "127.0.0.1"
	server["ServerPort"] = 8080

	b, err := json.Marshal(server)
	if err != nil {
		fmt.Println("JsonSerial err : ", err)
		return
	}
	fmt.Println(string(b))
}
